package com.apobates.jforum2.troll.forum.mapper;

import com.apobates.jforum2.troll.forum.entity.BoardGroup;
import com.apobates.jforum2.troll.forum.stub.vo.BoardGroupVo;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityTransformMapper;
import java.util.Optional;
import java.util.function.Function;

/**
 *
 * @author xiaofanku
 */
public class BoardGroupVoMapperEntity implements OptionalEntityTransformMapper<BoardGroup, BoardGroupVo>{
    @Override
    public Optional<BoardGroupVo> transform(Optional<BoardGroup> entity) {
        return entity.map(bg->{
          return mapper().apply(bg);
        });
    }

    /**
     * 转码ImageAddr
     * @since 20201125
     * @return
     */
    public static Function<BoardGroup, BoardGroupVo> mapper(){
        return boardGroup -> {
            BoardGroupVo bgv = new BoardGroupVo();
            bgv.setId(boardGroup.getId());
            bgv.setTitle(boardGroup.getTitle());
            bgv.setDescription(boardGroup.getDescription());
            bgv.setEntryDateTime(boardGroup.getEntryDateTime());
            bgv.setImageAddr(boardGroup.getImageAddr());
            bgv.setRanking(boardGroup.getRanking());
            bgv.setStatus(boardGroup.isStatus());
            bgv.setLink(BoardGroupVo.produceLink.apply(bgv.getId()));
            return bgv;
        };
    }
}